from google.appengine.ext import db
from Common.Profile import Profile
from Common.DuplicatedInstanceError import DuplicatedInstanceError
from Utility import UserRole

class SysAdmin(Profile):
    def put (self):
        # Make sure e-mails are unique for each user
        if (not self.is_saved()) and SysAdmin.get_by_key_name(self.UserName, self._parent_key):
            raise DuplicatedInstanceError ('SysAdmin.UserName', self.UserName)
        # make sure the role is SystemAdmin
        self.Role = UserRole.SystemAdmin
        # call the parent method
        db.Model.put (self)
        
    def TransactionPut(self):
        db.run_in_transaction(self.put)